package me.algo.array;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author guozheng
 * @date 2024/5/28
 */
public class A11 {
    public static void main(String[] args) {
        var nums = new int[]{1,4,3,8,5};
        System.out.println(findPeaks(nums));
    }

    /**
     * 2951. 找出峰值
     * @param mountain
     * @return
     */
    public static List<Integer> findPeaks(int[] mountain) {
        List<Integer> rtn = new ArrayList<>();
        if (Objects.isNull(mountain) || mountain.length < 3) {
            return rtn;
        }
        int idx = 1;
        int last = mountain.length - 1;
        while (idx < last) {
            if (isMount(mountain, idx)) {
                rtn.add(idx);
                idx = idx + 2;
            } else {
                idx++;
            }
        }
        return rtn;
    }

    private static boolean isMount(int[] ms, int k) {
        if (ms[k] > ms[k - 1] && ms[k] > ms[k + 1]) {
            return true;
        }
        return false;
    }
}
